package com.mm.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 
 * @ClassName: PageModel
 * @Description: 分页方法
 * @author 杨朝湖
 * @date 2020-11-04 10:25:34
 */
@Data
public class PageUtil<T> implements Serializable {

	private static final long serialVersionUID = 1L;

	private Integer pageNumber;// 总条数
	private Integer pageCount;// 总页数
	private Integer pageIndex;// 当前页
	private Integer pageSize;// 每页大小
	@JsonInclude(JsonInclude.Include.NON_NULL)
	private List<T> list;// 每页的内容
	@JsonInclude(JsonInclude.Include.NON_NULL)
	private Map<String, Object> mapInfo;

	public PageUtil(Integer pageNumber, Integer pageCount, Integer pageIndex, Integer pageSize, List<T> list) {
		super();
		this.pageNumber = pageNumber;
		this.pageCount = pageCount;
		this.pageIndex = (pageIndex + pageSize) / pageSize;
		this.pageSize = pageSize;
		this.list = list;
	}

	public PageUtil(Integer pageNumber, Integer pageCount, Integer pageIndex, Integer pageSize,
					Map<String, Object> mapInfo) {
		super();
		this.pageNumber = pageNumber;
		this.pageCount = pageCount;
		this.pageIndex = (pageIndex + pageSize) / pageSize;
		this.pageSize = pageSize;
		this.mapInfo = mapInfo;
	}

	public PageUtil() {
		super();
	}

	public Integer getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(Integer pageNumber) {
		this.pageNumber = pageNumber;
	}

	// 根据总记录数和每页记录数计算的到的总页数
	public Integer getPageCount() {
		return pageNumber % pageSize == 0 ? (pageNumber / pageSize) : (pageNumber / pageSize + 1);
	}

	public void setPageCount(Integer pageCount) {
		this.pageCount = pageCount;
	}

	public Integer getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(Integer pageIndex) {
		this.pageIndex = pageIndex;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public Map<String, Object> getMapInfo() {
		return mapInfo;
	}

	public void setMapInfo(Map<String, Object> mapInfo) {
		this.mapInfo = mapInfo;
	}

}
